﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SX.Utils
{
    public static class UrlHelper
    {
        /// <summary>
        /// 获取相对Url
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetUrl(string url)
        { 
            if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
                  || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
                  || url.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase)) && !url.StartsWith("/"))
            {
                
                if (url.StartsWith("~/"))
                {
                    url = url.Substring(2);
                } 

                if (!HostHelper.IsBaseApp)
                {
                    url =  HostHelper.AppPath + "/" + url;
                }
                else
                {
                    url =  "/" + url;
                }

            }
            return url;
        }
    }
}
